home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / examples / killprog < prev    next >
Encoding:
Text File  |  1994-02-08  |  1.3 KB  |  62 lines

  1. #!/usr/local/bin/icmake -qi
  2.  
  3. /*
  4.     Sample Icmake script. Kills programs; you can type 'killprog progname'
  5.     instead of having to look up the program PID using 'ps' and then typing
  6.     'kill -1 <PID number>'.
  7.     
  8.     For the installation: see the notes in the script file 'tolower'.
  9. */
  10.  
  11. #define VER    "1.00"
  12. #define TMPFILE    "/tmp/killprog.out"
  13.  
  14. int kill (string prog)
  15. {
  16.     int
  17.         nkilled;
  18.     list
  19.         readstat;
  20.     list
  21.         psline;
  22.         
  23.     system ("ps -al > " + TMPFILE);
  24.     
  25.     while (readstat = fgets (TMPFILE, (int) element (1, readstat)))
  26.     {
  27.         psline = strtok (element (0, readstat), " \n\t");
  28.         if (element (12, psline) == prog)
  29.         {
  30.             exec (P_NOCHECK, "kill", "-1", element (2, psline));
  31.             exec (P_NOCHECK, "kill", "-9", element (2, psline));
  32.             nkilled++;
  33.         }
  34.     }
  35.     
  36.     system ("rm " + TMPFILE);
  37.     return (nkilled);
  38. }
  39.  
  40. void main (int argc, list argv)
  41. {
  42.     echo (0);
  43.     
  44.     if (argc != 2)
  45.     {
  46.         printf ("\n"
  47.             "ICCE Program Slayer  V", VER, "\n"
  48.             "Copyright (c) ICCE, 1993. All rights reserved.\n"
  49.             "\n"
  50.             "Usage: killprog prog\n"
  51.             "Will send a 'kill -1' signal to all programs matching "
  52.                                 "'prog', followed\n"
  53.             "by a 'kill -9'.\n"
  54.             "\n");
  55.         exit (1);
  56.     }
  57.     
  58.     printf ("Processes slayed: ", kill (element (1, argv)), "\n");
  59.     
  60.     exit (0);
  61. }
  62.